In this document, we will present you the concept of our code, how you should be able to run it and one complex but essential function we have created.
For our project, we wanted to create an interface in which users can see to which countries they can travel, depending on their transportation mean, current location and time of travel they have.
We wanted to create 2 different windows:
Download and unzip the following folder “Travel organizer SARTOR_AUBIN_ROMBAUT_PANARD_FEYS-ORTLEPP” It contains the following files:
In Anaconda, create a new environment
In this environment, install Spyder
Launch Spyder and write the following in the command console:
a. pip install geopy
b. pip install tkintermapview
c. pip install Customtkinter
Run the python file MapWindowD.py
In the appearing introductory window, fill in your information:
a. Your name
b. Your current position (the position at which you want to start your travel)
Note that if you choose to enter a city which is not very well-known, it is better to enter the postal code of this city and even the country in which it is located in.
Also note that no matter the city chosen, the code will start its computations with the capital of the country in which the city chosen is in.
c. The maximum amount of time you have to travel
d. Your mode of transport: either plane or car (by car, the travel route will only be by land; the plane option allows the route to pass over the sea and oceans)
Note that it is not possible to choose both plane and car.
Click on Save then Next
A window called MapWindow appears, in which we can see the reachable countries pinned on the map
If the mode of transportation chosen was “car”, by clicking on the scroll menu, you will be able to see in blue the route to get to the different countries.
To see the informations about a country, click on the corresponding pin and they will appear in the window. Here is a key of all the information displayed:
a. The population of the country
b. The annual change in population in percentage form
c. The land area of the country in
d. The country’s population density in habitants per kilometer
e. The median age of the country’s population
For the case of a travel by car, the countries you need to pass by to reach your destination are listed.
You can also choose to change the appearance of the map, zoom and move it as you want, as well as the appearance of the window.
First, it has a database imported from the csv file “country_info”. It converts it into a dictionary that takes as key the abbreviation of the country and as values all possible information of the country, like its land area, its population and the most important the latitude and the longitude of its capital.
Indeed for the computation of the distance between two countries, we chose to only look at the distance between the capitals as the crow flies. We assumed that for turism people would tend to go to the capital of a country if they just visit it for a week-end. And in addition, when choosing to go there by plane, it should always be possible to join a capital city.
We used the GPS coordinates of the points to compute the distance between them in a straight line, even though it might not be really representative of reality. In the end, the differences between reality and what we compute are not so important.
The key function of our program is the function reachable_countries. Indeed it is the one that selects only the countries where the user can go within the time lap he has chosen and starting at its initial location.
The distance traveled is taking into consideration the means of transport you have chosen.
It combines several functions like :
get_dist_from_time_and_transport() → it converts the time into a distance according to the mean of transport chosen. It uses the average speeds of a plane and of a car. We’ve set them respectively to : 800 and 95 km/h.
convert_time_hours() → this function converts the time entered by the user on the form in hours/mins into hours only (in decimal form).
get_country_code_from_address(self.entry_position) → This function uses an API called “geopy” to find the code of the country associated with the position chosen as a parameter. This position can be a country, or a city inside of this country.
distance_countries(position,country_code) → thanks to this function we can get the distance between two positions when having the latitude and the longitude of the two points. Here as parameters we enter only country codes because the functions is working with the dictionary country_info where the keys are the country codes or abbreviations.
create_bfs(self, start) → this function corresponds to a graph traversal, using the Breadth-First Search technique. This graph traversal is done on a json file called country_neighbors.json, which is earlier on in the code turned into a dictionnary having:
The graph traversal consists in starting from the country, set as a parameter start, corresponding to the country chosen as starting position. The code then add the countries listed in its bordering countries and adds it to a “queue” list. For each of the countries in this list, the code will add to the queue list all of its bordering countries, as long as it was not already in the list. This country will then be deleted from the queue and added to the list of the reachable countries. This process is done as long as the list queue is not empty.
In the end, compute_reachable_countries verifies if the distance between our initial country and the potential final one is smaller than the distance that can be traveled in the user’s amount of time. If so, it is added to the reachable_country list.
In the special case of travel by car, it does not only find the reachable countries but it also finds the path (i.e. the different countries to pass by) to go there.
def compute_reachable_countries(self):
reachable_country = [ ]
time_hours = self.convert_time_hours()
position = self.get_country_code_from_address(self.entry_position)
dist=self.get_dist_from_time_and_transport(time_hours)
distance_countries=0
if self.choice_air.get()==1 :
for country_code in self.countries_info.keys() :
distance_countries = self.distance_countries(position,country_code)
if distance_countries < dist and distance_countries != 0 :
reachable_country.append(country_code)
print(reachable_country)
elif self.choice_earth.get()==1:
reachable_country , total_path, path = self.create_bfs(position)
print(reachable_country)
return reachable_country
To help us for the display of the map and windows, we used the following two libraries:
We also used an API (application programming interface) to help us with the whole geopgraphical aspect of our code, that is country delimitations, cities, coordinates etc…
Finally, we sometimes used help of chatGPT to help us correct some parts of the code and to create some basic functions. For instance we asked for :